#ifndef _ICM20602_H_
#define _ICM20602_H_
#include "main.h"
#include "stm32f4xx_hal.h"
#include "stdint.h"
 
#define My_PI 3.14159265358371f
 
//加速度量程
#define ICM20_ACCEL_FS_2G			(0<<3)
#define ICM20_ACCEL_FS_4G			(1<<3)
#define ICM20_ACCEL_FS_8G			(2<<3)
#define ICM20_ACCEL_FS_16G			(3<<3)
//角速度量程
#define ICM20_GYRO_FS_250			(0<<3)
#define ICM20_GYRO_FS_500			(1<<3)
#define ICM20_GYRO_FS_1000			(2<<3)
#define ICM20_GYRO_FS_2000			(3<<3)
//CONFIG DLPF，配置滤波
#define DLPF_BW_250         	0x00	//Rate=8k
#define DLPF_BW_176         	0x01
#define DLPF_BW_92          	0x02
#define DLPF_BW_41          	0x03
#define DLPF_BW_20          	0x04
#define DLPF_BW_10          	0x05
#define DLPF_BW_5           	0x06
#define DLPF_BW_328           	0x07	//Rate=8k
//ACCEL_CONFIG2
#define ACCEL_AVER_4         	(0x00<<4)	//Rate=8k
#define ACCEL_AVER_8			(0x01<<4)
#define ACCEL_AVER_16			(0x02<<4)
#define ACCEL_AVER_32			(0x03<<4)
//ACCEL_DLPF
#define ACCEL_DLPF_BW_218         	0x00	
//#define ACCEL_DLPF_BW_218         	0x01
#define ACCEL_DLPF_BW_99          	0x02
#define ACCEL_DLPF_BW_44          	0x03
#define ACCEL_DLPF_BW_21          	0x04
#define ACCEL_DLPF_BW_10          	0x05
#define ACCEL_DLPF_BW_5           	0x06
#define ACCEL_DLPF_BW_420           0x06	
 
 
uint8_t icm20602_init(void);
uint8_t icm20602_set_gyro_fullscale(uint8_t fs);
uint8_t icm20602_set_accel_fullscale(uint8_t fs);
uint8_t icm20602_get_accel_adc(short *ax,short *ay,short *az);
uint8_t icm20602_get_gyro_adc(short *gx,short *gy,short *gz);
uint8_t icm20602_get_gyro(float *gyro);
uint8_t icm20602_get_accel(float *accel);
float icm20602_get_temp(void);
uint8_t icm20602_get_gyro_adc_chuchang(short *gx,short *gy,short *gz);

typedef struct
{
    short ACCL_ADC[3];
    short GYRO_ADC[3];
    float ACCL[3];
    float GYRO[3];
    float Angel[3];
    float Temp;
    uint8_t GetData_Status;
}IMU;
extern IMU ICM_Data;

typedef struct
{
    float Gyro[3];
}OffSet;
extern OffSet IMU_OffSet;

uint8_t ICM20602_GyroOffSet(void);
void ICM20602_GetValue(void);
 
#endif
